package dialogs.ranking;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Comparator;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableRowSorter;

@SuppressWarnings("serial")
public class RankingView extends javax.swing.JPanel {
	
	private RankingTableModel tableModel;
	
	private JTable rankingTable;
	
	private TableRowSorter<RankingTableModel> sorter;
	
	public RankingView(RankingTableModel tableModel) {
		this.tableModel = tableModel;
		initComponents();
	}
	private void initComponents() {
		rankingTable = new JTable(tableModel);
        // Tabellen-Scrollbereich definieren
        rankingTable.setPreferredScrollableViewportSize(new Dimension(500, 80));
        rankingTable.setFillsViewportHeight(true);
        rankingTable.setRowHeight(18);
        
        //Konfiguration des sorters und hinzuf�gen zur Tabelle
        sorter = new TableRowSorter<RankingTableModel>(tableModel);
        sorter.setSortable( 0, false );
        Comparator<Integer> integerComp = new Comparator<Integer>() {
        	
			@Override
			public int compare(Integer i1, Integer i2) {
				return Integer.compare(i2, i1);
			}
		};
		 Comparator<Double> doubleComp = new Comparator<Double>() {

			@Override
			public int compare(Double d1, Double d2) {
				return Double.compare(d2, d1);
			}
				
		};
		sorter.setComparator(1, integerComp);
		sorter.setComparator(2, integerComp);
		sorter.setComparator(3, doubleComp);
		rankingTable.setRowSorter(sorter);
        this.setLayout(new BorderLayout() );
        JScrollPane scrollPane = new JScrollPane(rankingTable);
        this.add(scrollPane, BorderLayout.CENTER);
	}
}
